package com.demarc.pesquisas.web.converter;

import javax.faces.convert.FacesConverter;

import org.joda.time.DateTime;

@FacesConverter(value = "DateTimeConverter", forClass = DateTime.class)
public class DateTimeConverter extends AbstractJodaTimeConverter {
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected String getPattern() {
		return "dd/MM/yyyy HH:mm:ss";
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Object getAsObject(DateTime dateTime) {
		return dateTime;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getAsString(Object object) {
		String value = null;

		if (object instanceof DateTime) {
			value = ((DateTime) object).toString(getPattern());
		}
		return value;
	}
}
